<?php
/**
 * CException class file.
 * 这是框架所有异常类的基类.
 * @author Huan Song <iphper@yeah.net>
 * @version $Id: CException.php 1 2011-01-10 09:18:06Z huan.song $
 * @package system.base
 * @since 2.0
 */
class CException extends Exception
{
	/**
	 * @param string $key.
	 * @param array $params.
	 * @param integer $code 错误码.
	 * @param string $exception 异常名称.
	 */
	public function __construct($key, $params = array(), $code = 0, $exception = __CLASS__)
	{
		$exception = substr_replace($exception, 'A', 0, 1);
		$messages = require CConfig::getLanguageDir() . DS . $exception . '.php';
		$message = $messages[$key];
		if (is_array($params) && count($params) > 0)
		{
			foreach ($params as $key => $value)
			{
				if (is_array($value))
					$value = var_export($value, true);
					
				$message = str_replace($key, $value, $message);
			}
		}
		
		parent::__construct($message, $code);
	}
}
